<template>
    <div class="achievementYear">
        <el-form :inline="true" :model="ruleForm" class="demo-form-inline">
            <el-form-item label="报表名称：">
                <el-input placeholder="请输入报表名称" v-model.trim="ruleForm.reportName" maxlength="20"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="searchList" id="monitorEnter">查询</el-button>
                <el-button type="primary"  @click="generateReport">生成报表</el-button>
             </el-form-item>
        </el-form>

        <el-table :data="tableData" border>
            <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
            <el-table-column label="激励奖项" prop="reportFormName" align="center"></el-table-column>
            <el-table-column label="营收计提基数（元）" prop="revenueCalBase"  align="center"></el-table-column>
            <el-table-column label="计提比例（%）" prop="calBaseProportion" align="center"></el-table-column>
            <el-table-column label="计提金额（元）" prop="calBaseAmount" align="center"  :formatter="initCash" ></el-table-column>
            <el-table-column label="集团管理费计提比例（%）" prop="groupProportion" align="center"   ></el-table-column>
            <el-table-column label="集团管理费（元）" prop="groupCalAmount" align="center" :formatter="initCash" ></el-table-column>
            <el-table-column label="实发占比（%）" prop="realProportion" align="center" ></el-table-column>
            <el-table-column label="实发年终奖（元）" prop="bonusAmount" align="center" :formatter="initCash" ></el-table-column>
            <el-table-column label="操作" align="center">
                 <template slot-scope="scope">
                    <el-button type="text" @click="seehander(scope.row)">查看</el-button>
                    <el-button type="text" :disabled="scope.row.grantStatus == 1" @click="granthander(scope.row)">发放佣金</el-button>
                 </template> 
            </el-table-column>
        </el-table>

        <div class="pagebar">
            <el-pagination
                    background
                    layout="total, sizes, prev, pager, next"
                    :current-page.sync="ruleForm.pageNum"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="ruleForm.pageSize"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :total="totalSize">
            </el-pagination>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">
    import api from '@/api/apiPath'
    export default {
        name: 'achievementYear',
        title:'员工激励-年',
        data() {
            return {
                ruleForm: {
                    reportName: undefined,
                    pageNum: 1,
                    pageSize: 10,
                },
                totalSize: 0,
                tableData: []
            }
        },
        created() {
            this.getlist()
        },
        activated(){
            this.searchList()
        },
        methods: {
            generateReport(){
                this.$router.push({path:'/achievementYearReport'})
            },
            initCash(row, column, cellValue, index){
                if(!cellValue && typeof cellValue!="undefined" && cellValue!=0){
                     return '———'
                }
                if (cellValue < 0) {
                    return cellValue
                }
                if(cellValue !== 0 && cellValue >0){
                    return cellValue.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");
                }
                if(cellValue == 0){
                    return "0.00"
                }
            },
            handleCurrentChange() {
                this.getlist()
            },
            handleSizeChange(val) {
                this.ruleForm.pageSize = val
                this.getlist();
            },
            searchList(){
                this.ruleForm.pageNum = 1
                this.getlist()
            },
            //发放佣金
            granthander(val){
                 this.$confirm('是否发放佣金?', '提示', {
                      confirmButtonText: '确定',
                      cancelButtonText: '取消',
                      type: 'warning'
                    }).then(() => {
                        this.axios.post(api.REVENUEALLOTYEATGRANT,{id:val.id,grantStatus:1}).then(res=>{
                               if (res.data.code == 200) {
                                 this.$message({
                                     message: '发放成功',
                                     type: 'success'
                                 });
                                this.getlist()
                           }
                        })
                    }).catch(() => {
                      this.$message({
                        type: 'info',
                        message: '已取消'
                      });          
                    });
            },
            seehander(val){
                this.$router.push({path:'/achievementYearDetail',query:{allotYearId:val.id,year:val.year}})
            },
            getlist() {
                this.axios.post(api.REVENUEGETREYEARLIST, this.ruleForm).then((res) => {
                    if (res.data.code == 200) {
                        this.tableData = res.data.data.data;
                        this.totalSize = res.data.data.total;
                    }
                })
            }
        }
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="stylus">

</style>
